﻿@using Newtouch.Common.Operator;
@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<form id="form1">
    <div class="container" style="margin-top: 10px; margin-left: -4%; ">
        <ul class="nav nav-tabs" role="tablist" id="myTab" style="margin-left: 4%;">
            <li role="presentation"><a href="#basicInfo" role="tab" data-toggle="tab">基本信息</a></li>
        </ul>
        <div class="tab-content">
            <div role="tabpanel" class="tab-pane fade in active" style="padding-top: 20px; margin-right: 99px; margin-left:69px;" id="basicInfo">
                <table class="form">
                    <tr>
                        <th class="formTitle"><span class="required">*</span>组织机构：</th>
                        <td class="formValue formDdlSelectorTd">
                            <select id="OrganizeId" name="OrganizeId" class="form-control required">
                                <option value="">==请选择==</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle"><span class="required">*</span>病区编码：</th>
                        <td class="formValue formDdlSelectorTd">
                            <select id="bqCode" name="bqCode" class="form-control required">
                                <option value="">==请选择==</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle"><span class="required">*</span>病房：</th>
                        <td class="formValue formDdlSelectorTd">
                            <select id="bfCode" name="bfCode" class="form-control required">
                                <option value="">==请选择==</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle"><span class="required">*</span>编码：</th>
                        <td class="formValue">
                            <input type="text" class="form-control required" id="cwCode" name="cwCode" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle"><span class="required">*</span>名称：</th>
                        <td class="formValue">
                            <input type="text" class="form-control required" id="cwmc" name="cwmc" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle"><span class="required">*</span>床位类型：</th>
                        <td class="formValue formDdlSelectorTd">
                            @Html.DropDownList("cwlx", Newtouch.Infrastructure.EnumWardBedType.male.ToDescSelectList(), "==请选择==", new { @class = "form-control required" })
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle"><span class="required">*</span>床位等级：</th>
                        <td class="formValue formDdlSelectorTd">
                           <select id="cwdj" class="form-control required">
                               <option value="">==请选择==</option>
                           </select>
                        </td>
                    </tr>
                    @*<tr>
            <th class="formTitle">加床标志：</th>
            <td class="formValue">
                <div class="ckbox">
                    <input id="jcbz" name="jcbz" type="checkbox" checked="checked"><label for="jcbz"></label>
                </div>
            </td>
        </tr>
        <tr>
            <th class="formTitle"><span class="required">*</span>床位费：</th>
            <td class="formValue">
                <input type="text" class="form-control required" id="cwf" name="cwf" />
            </td>
        </tr>
        <tr>
            <th class="formTitle"><span class="required">*</span>等级医院加收费：</th>
            <th class="formValue">
                <input type="text" class="form-control required" id="djyyjsf" name="djyyjsf"  />
            </th>
        </tr>
        <tr>
            <th class="formTitle"><span class="required">*</span>病室治疗费：</th>
            <th class="formValue">
                <input type="text" class="form-control required" id="bszlf" name="bszlf"  />
            </th>
        </tr>
        <tr>
            <th class="formTitle"><span class="required">*</span>医用灭菌空气净化费：</th>
            <th class="formValue">
                <input type="text" class="form-control required" id="yymjkqjhf" name="yymjkqjhf" />
            </th>
        </tr>*@
                    <tr>
                        <th class="formTitle">有效：</th>
                        <td class="formValue">
                            <div class="ckbox">
                                <input id="zt" name="zt" type="checkbox" checked="checked"><label for="zt"></label>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</form>

<script>
    var cwId = $.request("cwId");
    var orgId = $.request("orgId");
    var keyValue = $.request("keyValue");

    $(function () {
        initControl();

        if (!!cwId) {
            $.najax({
                url: "/SysWardBed/GetFormJson?r=" + Math.random(),
                data: { cwId: cwId, orgId: orgId },
                dataType: "json",
                async: false,
                success: function (data) {
                    debugger;
                    $("#form1").formSerialize(data);
                }
            });
        }
        else {
            var newOrgId = $.request('orgId');
            if (newOrgId) {
                $("#OrganizeId").val(newOrgId).trigger('change');
            }
        }
    })

    function initControl() {
        //组织机构下拉框
        $("#OrganizeId").bindSelect({
            url: "/Organize/GetChildTreeSelectJson",
        });
        $("#OrganizeId").change(function () {
            //病区下拉
            $("#bqCode").bindSelect({
                url: "/SysWardBed/GetWardBindSelect?orgId=" + $('#OrganizeId').val()
            });
        });
        $("#bqCode").change(function () {
            //病房下拉
            $("#bfCode").bindSelect({
                url: "/SysWardRoom/GetWardRoomValidSelect?orgId=" + $('#OrganizeId').val() + "&bqCode=" + $('#bqCode').val()
            });
        });

        $('#cwdj').newtouchBindSelect({
            datasource: function () {
                var resultObjArr = new Array();
                $.each(top.clients.dataItems.BedGrade, function (idx, val) {
                    $('#cwdj').append('<option value="' + idx + '">' + val + '</option>');
                });
                return resultObjArr;
            }
        });
    }


    var anPrevOrg = null;
    $('#cwCode').focus(function () {
        var organizeId = $("#OrganizeId").val();
        if (!!!keyValue && ($.trim($(this).val()) === '' || organizeId != anPrevOrg)) {
            anPrevOrg = organizeId;
            $.najax({
                url: "/HOME/GetNewFieldUniqueValue?topOrgIdIsStar=false&initFieldLength=4&fieldName=xt_cw.cwCode&orgId=" + organizeId + "&r=" + Math.random(),
                dataType: "json",
                cache: false,
                success: function (data) {
                    $('#cwCode').val(data.data);
                }
            });
        }
    });

    //提交
    function submitForm() {
        if (!$('#form1').formValid()) {
            return false;
        }
        var params = $("#form1").formSerialize();
        $.submitForm({
            url: "/SysWardBed/SubmitForm?cwId=" + cwId,
            param: params,
            success: function () {
                $.currentWindow().$("#gridList").resetSelection();
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
</script>
